/*******************************************************************************
 * Copyright (c) 2012 Daniele Parisi.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Daniele Parisi
 *     neb.inf@gmail.com
 *     http://www.danieleparisi.com/
 ******************************************************************************/
package org.jxreport.core.views.chart.line;

import java.util.LinkedList;
import java.util.List;

import org.jxreport.core.Cell;
import org.jxreport.core.Row;
import org.jxreport.core.Table;
import org.jxreport.core.XMLUtils;
import org.jxreport.core.XMLValues;
import org.w3c.dom.Element;

public class Point{//<E, T extends Iterable<E>>{
	public double x; 
	public double y;
	
	public Point(){}
	
	public Point(Element pointElement)
	{
		this.setX(XMLUtils.getIntValue(pointElement, XMLValues.X));
		this.setY(XMLUtils.getIntValue(pointElement, XMLValues.Y));
	}
	
	public static List<Point> getPointsByData(Element pointsElement, Table table)
	{
		List<Point> list = new LinkedList<Point>();
		//T instances = table.get(XMLUtils.getIntValue(pointsElement, XMLValues.INSTANCES_INDEX));
		for (Row row : table) {
			
			Cell x = row.get(XMLUtils.getIntValue(pointsElement, XMLValues.X_INDEX));
			Cell y = row.get(XMLUtils.getIntValue(pointsElement, XMLValues.Y_INDEX));

			Point point = new Point();
			point.setX((Double)x.getValue());
			point.setY((Double)y.getValue());
			//point.setX(row.get(XMLUtils.getIntValue(pointsElement, XMLValues.X_INDEX)));
			//point.setY(instance.value(XMLUtils.getIntValue(pointsElement, XMLValues.Y_INDEX)));
			
			list.add(point);
		}
		
		return list;
	}
	
	/*
	public static Point getPointByXMLTag(Element pointElement)
	{
		Point point = new Point();
		point.setX(XMLUtils.getIntValue(pointElement, XMLValues.X));
		point.setY(XMLUtils.getIntValue(pointElement, XMLValues.Y));
		
		return point;
	}
	*/
	
	/*
	public static List<Point> getPointsByData(Element pointsElement, List<Instances> listInstances)
	{
		List<Point> list = new ArrayList<Point>();
		
		Instances instances = listInstances.get(XMLUtils.getIntValue(pointsElement, XMLValues.INSTANCES_INDEX));
		System.out.println("SIZE LIST(" + XMLUtils.getIntValue(pointsElement, XMLValues.INSTANCES_INDEX) + "): " + instances.size());
		for (Instance instance : instances) {
			Point point = new Point();
			point.setX(instance.value(XMLUtils.getIntValue(pointsElement, XMLValues.X_INDEX)));
			point.setY(instance.value(XMLUtils.getIntValue(pointsElement, XMLValues.Y_INDEX)));
			
			list.add(point);
		}
		
		return list;
	}
	*/
	public double getX() {
		return x;
	}
	
	public void setX(double x) {
		this.x = x;
	}
	
	public double getY() {
		return y;
	}
	
	public void setY(double y) {
		this.y = y;
	}
}
